package com.qingpeng.pay.activity;

import android.os.Bundle;
import android.view.View;

import com.qingpeng.pay.R;
import com.qingpeng.pay.adapter.CodeLIstAdapter;
import com.qingpeng.pay.api.Host;
import com.qingpeng.pay.api.RedBag;
import com.qingpeng.pay.base.BaseActivity;
import com.qingpeng.pay.beans.CodeListBean;
import com.qingpeng.pay.okhttp.RetrofitCreateHelper;
import com.qingpeng.pay.utils.ToastUtils;
import com.qingpeng.pay.views.TitleBar;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class CodeListActivity extends BaseActivity {

    @BindView(R.id.title)
    TitleBar title;
    private List<CodeListBean.DataProductBean> mData;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_code_list;
    }

    @Override
    protected int getRootViewId() {
        return 0;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return R.id.recycler;
    }

    @Override
    protected void onResume() {
        super.onResume();
        title.getLlLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Call<CodeListBean> codelist = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).codelist();
        codelist.enqueue(new Callback<CodeListBean>() {
            @Override
            public void onResponse(Call<CodeListBean> call, Response<CodeListBean> response) {
                CodeListBean body = response.body();
                if (body.getStatus() != 1) {
                    ToastUtils.showToast(CodeListActivity.this, body.getInfo());
                    return;
                }
                mData = body.getData();
                initAdapter();
            }

            @Override
            public void onFailure(Call<CodeListBean> call, Throwable t) {
                ToastUtils.showToast(CodeListActivity.this, "网络请求错误,请稍后重试");
            }
        });
    }

    @Override
    protected void initAdapter() {
        mAdapter = new CodeLIstAdapter(R.layout.item_code_list);
        mAdapter.setNewData(mData);
        super.initAdapter();
    }
}
